#include <iostream>
#include <queue>
#include <vector>
using namespace std;

const int kMaxN = 3e5 + 10;
const int kMaxM = 3e5 + 10;
const long long kInf = 1e18;

struct Edge {
  int to, no, w;
};

vector<Edge> g[kMaxN];
int e_w[kMaxM], edge_id[kMaxN];
long long dist[kMaxN];

void Dijkstra(int n, int s = 1) {
  priority_queue<pair<long long, int>> pq;

  fill(dist, dist + n + 1, kInf);
  dist[s] = 0;
  pq.emplace(-dist[s], s);
  while (!pq.empty()) {
    long long d = -pq.top().first;
    int u = pq.top().second;

    pq.pop();
    if (dist[u] != d) {
      continue;
    }
    for (const Edge &e : g[u]) {
      if (dist[e.to] > d + e.w) {
        dist[e.to] = d + e.w;
        pq.emplace(-dist[e.to], e.to);
      }
      if (dist[e.to] == d + e.w && e_w[edge_id[e.to]] > e.w) {
        edge_id[e.to] = e.no;
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m, s;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, w;

    cin >> u >> v >> w;
    g[u].emplace_back(Edge{v, i, w});
    g[v].emplace_back(Edge{u, i, w});
    e_w[i] = w;
  }
  e_w[0] = 1e9 + 10;
  cin >> s;
  Dijkstra(n, s);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i != s) {
      ans += e_w[edge_id[i]];
    }
  }
  cout << ans << "\n";
  for (int i = 1; i <= n; i++) {
    if (i != s) {
      cout << edge_id[i] << " ";
    }
  }
  cout << "\n";
  return 0;
}